package com.shadow.baiqun.delegate;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.shadow.baiqun.R;
import com.shadow.baiqun.listener.ISignListener;
import com.shadow.core.account.AccountManager;
import com.shadow.core.account.IUserChecker;
import com.shadow.core.delegate.ShadowDelegate;

/**
 * @author zy
 * on 2018/5/19
 */
public class RootDelegate extends ShadowDelegate {

    public static RootDelegate create() {
        return new RootDelegate();
    }

    private ISignListener mSignListener;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof ISignListener) {
            mSignListener = (ISignListener) activity;
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_root;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
         checkHasLogin();
    }

    private void checkHasLogin() {
        AccountManager.checkAccount(new IUserChecker() {
            @Override
            public void onSignIn() {
                if (mSignListener != null) {
                    mSignListener.onSignInSuccess();
                }
            }

            @Override
            public void onNotSignIn() {
                if (mSignListener != null) {
                    mSignListener.onSignInFailed();
                    // mSignListener.onSignInSuccess();
                }
            }
        });
    }


}
